<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('车辆申请列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>借用车辆：</label>
                            <input type="text" name="carList.name"/>
                        </li>
                        <li>
                            <label>车辆颜色：</label>
                            <input type="text" name="carList.color"/>
                        </li>
                        <li>
                            <label>车牌：</label>
                            <input type="text" name="carList.card"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:process:remove">
                <i class="fa fa-remove"></i> 删除
            </a>

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:process:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:process:remove')}]];
    var prefix = ctx + "system/process";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "车辆申请",
            columns: [{
                checkbox: true
            },
                {
                    field: 'processId',
                    title: '编号',
                    // visible: false
                },
                {
                    field: 'carList.name',
                    title: '车辆名称'
                },
                {
                    field: 'carList.color',
                    title: '颜色'
                },
                {
                    field: 'carList.card',
                    title: '车牌'
                },
                {
                    field: 'createrName',
                    title: '创建人'
                },
                {
                    field: 'createdTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];

                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.processId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        console.log(row.status);
                        if (row.status === "未归还" || row.status === "外借") {
                            actions.push('<a class="btn btn-success btn-xs edits' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.processId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-success btn-xs apply" href="javascript:void(0)" onclick="applyCar(\'' + row.usedCar + '\')"><i class="fa fa-edit"></i>归还</a> ');
                        }else{
                            actions.push('<a class="btn btn-success btn-xs edits' + editFlag + '" href="javascript:void(0)" disabled="true"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-success btn-xs apply" href="javascript:void(0)" disabled="true"><i class="fa fa-edit"></i>归还</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function applyCar(id) {
        $.modal.disable
        $.modal.confirm("确认归还嘛", function () {
            $.operate.get(prefix + "/back/" + id, function () {
                console.log("ok")
            });
        });
    }


</script>
</body>
</html>